package org.lds.logger.config.appender.async.disruptor;

import com.lmax.disruptor.EventHandler;
import org.lds.logger.config.appender.Appender;
import org.lds.logger.config.appender.async.AsyncAppenderGroup;
import org.lds.logger.event.LoggerEvent;

public class DefaultLoggerEventConsumer implements EventHandler<LoggerEvent> {
    private AsyncAppenderGroup asyncAppenderGroup;

    public DefaultLoggerEventConsumer(AsyncAppenderGroup asyncAppenderGroup) {
        this.asyncAppenderGroup = asyncAppenderGroup;
    }

    @Override
    public void onEvent(LoggerEvent loggerEvent, long sequence, boolean endOfBatch) throws Exception {
        for (Appender appender : asyncAppenderGroup.getAsyncAppenderList()) {
            appender.append(loggerEvent);
        }
    }
}
